import { get, post, put, del } from '@/utils/http/request'
import { R, P } from '@/utils/http/type'
export * from './types/user'
import {
  AddUserInfoType,
  DepTreeType,
  RoleSelectType,
  UpdateUserInfoType,
  UserDetailType,
  UserListType,
} from './types/user'

/**
 * 更新用户
 * @param data
 * @returns
 */
export const updateUserDetail = (data: UpdateUserInfoType) => {
  return put('/user/update', data)
}
/**
 * 编辑时用户数据
 * @param id  用户id
 * @returns
 */
export const getUserDetail = (id: string) => {
  return get<R<UserDetailType>>(`/user/detail/${id}`)
}

/**
 * 删除用户
 * @param id
 * @returns
 */
export const deleteUser = (id: any) => {
  return del(`/user/delete/${id}`)
}

/**
 * 添加用户
 * @param data
 * @returns
 */
export const addUser = (data: AddUserInfoType) => {
  return post('/user/add', data)
}

/**
 * 获取部门树
 * @returns
 */
export const getDepTree = () => {
  return get<R<DepTreeType[]>>('/department/tree')
}

/**
 * 获取用户列表
 * @param data
 * @returns
 */
export const getUserList = (data: {
  page: number
  size: number
  username?: string
  depName?: string
}) => {
  return get<P<UserListType>>('/user/list', data)
}
/**
 * 获取角色select
 */
export const getRoleSelect = () => {
  return get<R<RoleSelectType[]>>('/role/select')
}
